Skip to content

Create 387. First Unique Character in a String#27

Open
Apo-Matchbox wants to merge 2 commits intomainfrom
387.-First-Unique-Character-in-a-String
Open

Create 387. First Unique Character in a String#27
Apo-Matchbox wants to merge 2 commits intomainfrom
387.-First-Unique-Character-in-a-String

Conversation

@Apo-Matchbox
Copy link
Copy Markdown
Owner

for (char c : s) {
frequency[c - 'a']++;
}
for (int i = 0; i < static_cast<int>(s.size()); ++i) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ちゃんと int に static_cast していて、えらいなと思いました。

Co-authored-by: t9a-dev <t9a.dev@icloud.com>
public:
int firstUniqChar(const std::string& s) {
std::vector<int> frequency(26, 0);
std::array<int, 26> frequency{};
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます!

ご指摘の通りだと思いました!要素数が変わらない場面では固定長配列を選ぶ、という視点は今まであまり意識していなかったので勉強になりました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants